{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d8fcd1a9-d7c5-4049-bfff-27dbc49b029d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from coco_evaluation import CocoDetectionEvaluator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa90e100-072b-4f55-999c-a8e03d56fe87",
   "metadata": {},
   "outputs": [],
   "source": [
    "evaluator = CocoDetectionEvaluator('./data/coco/annotations/instances_val2017.json')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "585276a5-cfb2-4e2b-a9de-30a46cbf30c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "results, per_class_results = evaluator.evaluate('./prediction_Qwen2_vl_2B_GRPO_coco.json', './results')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "92d76ac4-44aa-43b5-8123-d871453e6750",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "### mAP and AP for all categories\n",
    "results, per_class_results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "014151c7-5a90-4d46-9782-7195cb7147ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "### mAP and AP for selected categories\n",
    "selected_cate = ['bus', 'train', 'fire hydrant', 'stop sign', 'cat', 'dog', 'bed', 'toilet']\n",
    "# selected_cate = ['mouse', 'fork', 'hot dog', 'cat', 'airplane', 'suitcase', 'parking meter', 'sandwich', 'train', 'hair drier', 'toilet', 'toaster', 'snowboard', 'frisbee', 'bear']\n",
    "results, per_class_results\n",
    "AP_sum = 0\n",
    "for item in per_class_results:\n",
    "    for key, value in item.items():\n",
    "        if key in selected_cate:\n",
    "            print(f\"Key: {key}, Value: {value}\")\n",
    "            AP_sum += value\n",
    "print(\"mAP for selected categories: \", (AP_sum)/(len(selected_cate)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
